package com.imoblife.brainwavestus.util;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DBHelper extends SQLiteOpenHelper {
	
	public static final String TAG = "DBHelper";
	
	public DBHelper(Context ctx){
		
		super(ctx, DBUtil.DATABASE_NAME, null, DBUtil.DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		
		//create product table
		db.execSQL(DBUtil.CREATE_PRODUCT_TABLE);
		db.execSQL(DBUtil.CREATE_TAPJOY_TABLE);
		db.execSQL(DBUtil.CREATE_DOWNLOAD_TASK_TABLE);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		
		//drop product table and rebuild it
		db.execSQL("DROP TABLE IF EXISTS " + DBUtil.PRODUCT_TB_NAME);
		db.execSQL("DROP TABLE IF EXISTS " + DBUtil.TAPJOY_TB_NAME);
		db.execSQL("DROP TABLE IF EXISTS " + DBUtil.DOWN_TASK_TB_NAME);
		onCreate(db);
	}
}